package com.opensource.baowebcon.controller;

import com.opensource.common.Result.ResponseResult;
import com.opensource.common.contant.RedisKey;
import com.opensource.common.utils.CommonUtil;
import com.opensource.datamodel.dto.redis.RankDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author wzh
 * @date 2024/5/9
 * @apiNote
 */
@Api(tags = "投资理财产品")
@RestController
@RequestMapping("/invest")
public class InvestController extends BaseController {

    /*投资排行榜*/
    @ApiOperation(value = "投资排行榜", notes = "显式投资金额最高的3位用户信息")
    @GetMapping("/getRank")
    public ResponseResult getRank() {
        Set<ZSetOperations.TypedTuple<String>> zSet = redisCache.getReverseCacheZSet(RedisKey.KEY_INVEST_RANK);

        ArrayList<RankDto> rankList = new ArrayList<>();
        zSet.forEach(item -> {
            String phone = String.valueOf(item.getValue()); // 如果是Long类型，这样可以转换为String
            String tuoMinPhone = CommonUtil.tuoMinPhone(phone);

            double score = item.getScore(); // 分数对应于money

            RankDto rankItem = new RankDto(tuoMinPhone, score); // 创建RankDto对象
            rankList.add(rankItem);
        });


        return ResponseResult.okResult(rankList);
    }


}
